/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.quality4spl.fm.cvm.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import org.quality4spl.fm.cvm.CDMApplication;
import org.quality4spl.fm.cvm.ConfigDecisionModel;
import org.quality4spl.fm.cvm.CvmPackage;
import org.quality4spl.fm.cvm.NameSequence;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>CDM Application</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.quality4spl.fm.cvm.impl.CDMApplicationImpl#getSourceConfigurations <em>Source Configurations</em>}</li>
 *   <li>{@link org.quality4spl.fm.cvm.impl.CDMApplicationImpl#getTargetConfigurations <em>Target Configurations</em>}</li>
 *   <li>{@link org.quality4spl.fm.cvm.impl.CDMApplicationImpl#getAppliedCDM <em>Applied CDM</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class CDMApplicationImpl extends CVMElementImpl implements CDMApplication {
	/**
	 * The cached value of the '{@link #getSourceConfigurations() <em>Source Configurations</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSourceConfigurations()
	 * @generated
	 * @ordered
	 */
	protected EList<NameSequence> sourceConfigurations;

	/**
	 * The cached value of the '{@link #getTargetConfigurations() <em>Target Configurations</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTargetConfigurations()
	 * @generated
	 * @ordered
	 */
	protected EList<NameSequence> targetConfigurations;

	/**
	 * The cached value of the '{@link #getAppliedCDM() <em>Applied CDM</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAppliedCDM()
	 * @generated
	 * @ordered
	 */
	protected ConfigDecisionModel appliedCDM;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected CDMApplicationImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return CvmPackage.Literals.CDM_APPLICATION;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<NameSequence> getSourceConfigurations() {
		if (sourceConfigurations == null) {
			sourceConfigurations = new EObjectContainmentEList<NameSequence>(NameSequence.class, this, CvmPackage.CDM_APPLICATION__SOURCE_CONFIGURATIONS);
		}
		return sourceConfigurations;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<NameSequence> getTargetConfigurations() {
		if (targetConfigurations == null) {
			targetConfigurations = new EObjectContainmentEList<NameSequence>(NameSequence.class, this, CvmPackage.CDM_APPLICATION__TARGET_CONFIGURATIONS);
		}
		return targetConfigurations;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ConfigDecisionModel getAppliedCDM() {
		if (appliedCDM != null && appliedCDM.eIsProxy()) {
			InternalEObject oldAppliedCDM = (InternalEObject)appliedCDM;
			appliedCDM = (ConfigDecisionModel)eResolveProxy(oldAppliedCDM);
			if (appliedCDM != oldAppliedCDM) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, CvmPackage.CDM_APPLICATION__APPLIED_CDM, oldAppliedCDM, appliedCDM));
			}
		}
		return appliedCDM;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ConfigDecisionModel basicGetAppliedCDM() {
		return appliedCDM;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setAppliedCDM(ConfigDecisionModel newAppliedCDM) {
		ConfigDecisionModel oldAppliedCDM = appliedCDM;
		appliedCDM = newAppliedCDM;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CvmPackage.CDM_APPLICATION__APPLIED_CDM, oldAppliedCDM, appliedCDM));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case CvmPackage.CDM_APPLICATION__SOURCE_CONFIGURATIONS:
				return ((InternalEList<?>)getSourceConfigurations()).basicRemove(otherEnd, msgs);
			case CvmPackage.CDM_APPLICATION__TARGET_CONFIGURATIONS:
				return ((InternalEList<?>)getTargetConfigurations()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case CvmPackage.CDM_APPLICATION__SOURCE_CONFIGURATIONS:
				return getSourceConfigurations();
			case CvmPackage.CDM_APPLICATION__TARGET_CONFIGURATIONS:
				return getTargetConfigurations();
			case CvmPackage.CDM_APPLICATION__APPLIED_CDM:
				if (resolve) return getAppliedCDM();
				return basicGetAppliedCDM();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case CvmPackage.CDM_APPLICATION__SOURCE_CONFIGURATIONS:
				getSourceConfigurations().clear();
				getSourceConfigurations().addAll((Collection<? extends NameSequence>)newValue);
				return;
			case CvmPackage.CDM_APPLICATION__TARGET_CONFIGURATIONS:
				getTargetConfigurations().clear();
				getTargetConfigurations().addAll((Collection<? extends NameSequence>)newValue);
				return;
			case CvmPackage.CDM_APPLICATION__APPLIED_CDM:
				setAppliedCDM((ConfigDecisionModel)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case CvmPackage.CDM_APPLICATION__SOURCE_CONFIGURATIONS:
				getSourceConfigurations().clear();
				return;
			case CvmPackage.CDM_APPLICATION__TARGET_CONFIGURATIONS:
				getTargetConfigurations().clear();
				return;
			case CvmPackage.CDM_APPLICATION__APPLIED_CDM:
				setAppliedCDM((ConfigDecisionModel)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case CvmPackage.CDM_APPLICATION__SOURCE_CONFIGURATIONS:
				return sourceConfigurations != null && !sourceConfigurations.isEmpty();
			case CvmPackage.CDM_APPLICATION__TARGET_CONFIGURATIONS:
				return targetConfigurations != null && !targetConfigurations.isEmpty();
			case CvmPackage.CDM_APPLICATION__APPLIED_CDM:
				return appliedCDM != null;
		}
		return super.eIsSet(featureID);
	}

} //CDMApplicationImpl
